
#ifndef __W25Q64_H__
#define __W25Q64_H__

#include "include.h"
#include "stdio.h"

	#ifdef W25Q64_VAR
		#define W25Q64_EXT	
	#else
		#define W25Q64_EXT extern
	#endif

typedef uint32_t WORD;
typedef uint8_t 	BYTE; 
typedef uint64_t 	DWORD;

		
#define FLASH_MEMORY_SIZE		0x800000

#define LOOPSIZE			256 	//256		
		
typedef struct _firmindex
{
	WORD Index;
	WORD xs;
	WORD ys;
	WORD Height;
	WORD Width;
	//WORD dummy;
	BYTE TimeDuration;		// ms unit
	BYTE CHK;
	DWORD Address;
} firmware_index;
typedef struct _msgindex
{
	WORD messagenumber;		// 2

	WORD msn[20];			// 40
	WORD time;				// 2
	WORD nextmsg;			// 2
	BYTE totalnumber;		// 1
	BYTE msn_checksum;		// 1
} message_index;

typedef struct _firm
{
	firmware_index firmware_table[1024];
	message_index msg_table[1024];
	BYTE firmwarespace[FLASH_MEMORY_SIZE-0x10000];			// 32 M Byte and 16 M Word
} BIN_FILE;






typedef struct _disbuffer
{
	BYTE start[6];
	WORD display_payload[LOOPSIZE];
} DISPLAY_AREA;




//firmware_index

W25Q64_EXT volatile BYTE keycheckflag;
W25Q64_EXT volatile BYTE timeout_draw;
W25Q64_EXT BYTE DummyRead,DummyWrite;
W25Q64_EXT volatile BYTE new_pack;
W25Q64_EXT BYTE ProgrammerState;
W25Q64_EXT WORD current_writeblock;
W25Q64_EXT volatile unsigned char rev_index;
W25Q64_EXT BYTE writeflash[];
W25Q64_EXT BYTE protocol_timeout;
W25Q64_EXT DWORD lastAddress;
W25Q64_EXT volatile BYTE display_bufferflag;
W25Q64_EXT volatile DWORD display_piexlindex;
W25Q64_EXT WORD PictureVersion,customer;
W25Q64_EXT DWORD GloableAddr;
W25Q64_EXT BYTE display_bufferindex;
W25Q64_EXT DISPLAY_AREA display_bufferA;//[DMASIZE];
W25Q64_EXT DISPLAY_AREA display_bufferB;//[DMASIZE];
W25Q64_EXT DISPLAY_AREA display_bufferC;//[DMASIZE];

W25Q64_EXT volatile unsigned char Operate_timeout,amountflag;


W25Q64_EXT DWORD GlobleAddr;
W25Q64_EXT WORD xstartaddr,ystartaddr;
W25Q64_EXT WORD width,height;
W25Q64_EXT WORD endpackcount;
W25Q64_EXT volatile BYTE locked;
W25Q64_EXT volatile DWORD rec_index;
W25Q64_EXT volatile WORD ms_count;
//W25Q64_EXT volatile WORD message_index ;
W25Q64_EXT volatile BYTE command_arrive;
W25Q64_EXT volatile BYTE Uart_Inbuffer[];
W25Q64_EXT volatile BYTE Uart_buffer[];
W25Q64_EXT volatile BYTE Uart_Outbuffer[];
W25Q64_EXT volatile BYTE picture_draw_finished;
//W25Q64_EXT volatile COM_PACK commands,Prev_commands,answer;
W25Q64_EXT volatile BYTE pictureloopcount;
W25Q64_EXT volatile BYTE _100ms_timer;
W25Q64_EXT volatile BYTE total_control_num;
W25Q64_EXT volatile BYTE clear_screen;
W25Q64_EXT WORD pos[2];
W25Q64_EXT WORD j;
W25Q64_EXT WORD Control_Position[21][5];

//W25Q64_EXT volatile message_header Globle_MsgHeader,Globle_MsgHeader_Prev;
W25Q64_EXT volatile unsigned char continue_message,Icon_duration_time,NextIconIndex;
W25Q64_EXT volatile unsigned char message_drawing,parameters_showing;
W25Q64_EXT volatile unsigned int x_offset;



W25Q64_EXT void Spi1_ReadFlash_config(void);
void Spi1_Read_FlashId();
void Spi1ReadFlashData(uint32_t Addr,uint8_t *databuf,uint16_t len);



#endif





